#! /bin/sh
#
# Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Ruediger Oertel <ro@suse.de>, 1996-2002
#         Werner Fink <werner@suse.de>, 1996-2002
#         Burchard Steinbild <feedback@suse.de>, 1996-2000
#         Florian La Roche <feedback@suse.de>, 1996
#
# /etc/init.d/boot
#
# first script to be executed from init on system startup
#

. /etc/rc.status
. /etc/sysconfig/boot
echo "Running $0"

rc_reset
echo -n "Mounting /proc device"
mount -n -t proc proc /proc
rc_status -v -r

echo -n "Mounting /dev/pts"
optpts="-o mode=0620,gid=5"
mount -n -t devpts $optpts devpts /dev/pts
rc_status -v -r

#
# Save old terminal settings and set -nl to avoid staircase
# effect, do not lock scrolling, and avoid break characters.
#
otty=$(stty -g)
if test "$FLOW_CONTROL" = "yes" ; then
    stty -nl  ixon ignbrk -brkint 0>&1
else
    stty -nl -ixon ignbrk -brkint 0>&1
fi

#
# Should we ask for interactive boot mode
#
DO_CONFIRM=""
read -t 2 check < /proc/cmdline 2> /dev/null
case "$check" in
    *confirm*) DO_CONFIRM=yes ;;
esac
test -z "$CONFIRM_PROMPT_TIMEOUT" && CONFIRM_PROMPT_TIMEOUT=5
if test "$PROMPT_FOR_CONFIRM" = "yes" -a "$DO_CONFIRM" != "yes" ; then
    echo -en "${extd}Enter Interactive startup mode?${norm}"
    rc_timer_on "$CONFIRM_PROMPT_TIMEOUT" 37
    read -t "$CONFIRM_PROMPT_TIMEOUT" -n 1 -p " ${extd}y${norm}/[${extd}n${norm}]("${CONFIRM_PROMPT_TIMEOUT}s") " answer
    rc_timer_off
    case "$answer" in
    [yYiI]) DO_CONFIRM=yes ;;
    *)      DO_CONFIRM=    ;;
    esac
    unset answer
    echo
fi
export DO_CONFIRM

#
# Start blogd, requires /proc and /dev/pts.
# Export the real device in variable REDIRECT.
#
REDIRECT="`showconsole 2>/dev/null`"
test -x /sbin/blogd -a -n "$REDIRECT" && /sbin/blogd $REDIRECT
: ${REDIRECT:=/dev/tty}
export REDIRECT

#
# Start bootup client scripts.
#
if test -d /etc/init.d/boot.d/ ; then
    for i in /etc/init.d/boot.d/S*; do
	test -f $i || continue
	if test "$DO_CONFIRM" = "yes" ; then
	    rc_confirm -t 5 "Start bootup script ${i##*/S[0-9][0-9]}" < $REDIRECT > $REDIRECT 2>&1
	    case "$?" in
	    0) true     ;;
	    1) continue ;;
	    2) DO_CONFIRM=""
	    esac
	fi
	if test -x "$i" ; then
	    # Active boot scripts, should have their own messages
	    $i start
	else
	    # Old boot scripts, may not have any message
	    echo Running $i
	    /bin/sh $i b
	    rc_status -v1 -r
	fi
    done
fi

#
# Start user defined bootup script.
#
if test -f /etc/init.d/boot.local ; then
        echo "Running /etc/init.d/boot.local"
        /bin/sh /etc/init.d/boot.local
	rc_status -v1 -r
fi

#
# Stop blogd
#
test -x /sbin/blogd && killproc -QUIT /sbin/blogd

#
# Remember for master resource script
#
if test "$DO_CONFIRM" = "yes" ; then
    touch /var/run/do_confirm
fi

#
# Restore old terminal settings
#
stty $otty 0>&1

#
# Let YaST2 finish its installation, if you installed with YaST2
#
if test -f /var/lib/YaST2/runme_at_boot ; then
    HOSTTYPE=$(uname -m)
    rc_splash "YaST"
    exec 0<> $REDIRECT 1>&0 2>&0
    # if yast2 failed, this ensures proper system setup
    touch /var/lib/YaST2/run_suseconfig
    if test -x /usr/lib/YaST2/bin/YaST2.firstboot; then
	/usr/lib/YaST2/bin/YaST2.firstboot
    else
	# oops, yast2 not installed
	rm -f /var/lib/YaST2/runme_at_boot
    fi
fi
# run SuSEconfig (with args) if needed
if test -f /var/lib/YaST2/run_suseconfig ; then
    /sbin/SuSEconfig `cat /var/lib/YaST2/run_suseconfig`
    rm -f /var/lib/YaST2/run_suseconfig
fi

rc_reset
exit 0
